package com.ksyun.ks3.demo;

import com.ksyun.ks3.dto.GetObjectResult;
import com.ksyun.ks3.dto.Ks3Object;
import com.ksyun.ks3.dto.ObjectMetadata;
import com.ksyun.ks3.dto.ResponseHeaderOverrides;
import com.ksyun.ks3.service.request.GetObjectRequest;

/**
 * @author lijunwei[lijunwei@kingsoft.com]  
 * 
 * @date 2014年12月1日 下午5:19:00
 * 
 * @description 
 **/
public class GetObjectDemo extends AbstractDemo{
	public GetObjectResult getObject(){
		GetObjectRequest request = new GetObjectRequest("test.bucket","object.txt");
		
		//重写返回的header
		ResponseHeaderOverrides overrides = new ResponseHeaderOverrides();
		overrides.setContentType("text/html");
		//.......
		overrides.setContentEncoding("UTF-8");
		request.setOverrides(overrides);
		//只接受数据的0-10字节。通过控制该项可以实现分块下载
		request.setRange(0,10);
		GetObjectResult result = client.getObject(request);
		
		Ks3Object object = result.getObject();
		//获取object的元数据
		ObjectMetadata meta = object.getObjectMetadata();
		//当分块下载时获取文件的实际大小，而非当前小块的大小
		Long length = meta.getInstanceLength();
		//获取object的输入流
		object.getObjectContent();
		
		return result;
	}
}
